#! /usr/bin/python
import sys
import os

cmd = ""
result=""

cmd ="mkdir result"
os.system(cmd)

cmd ="mkdir result/time"
os.system(cmd)

cmd ="mkdir result/event"
os.system(cmd)

cmd ="mkdir result/cpu"
os.system(cmd)

for colNum in range(1,11):
    cmd= "rm -rf sortTable* sortKey"
    os.system(cmd)
    cmd = "./sortBinaryGen 1 " + str(colNum) + " 4"
    os.system(cmd)
    cmd = "chmod 777 sortTable* sortKey"
    os.system(cmd)

    result = "result/time/" + str(colNum) + "_noprof"
    cmd = "./sortTest sortTable " + str(colNum)+ " 4 > " + result
    os.system(cmd)
    os.system(cmd)

    result = "result/time/" + str(colNum) 
    cmd = "nvprof ./sortTest sortTable " + str(colNum)+ " 4 > " + result
    os.system(cmd)
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_mem_request" 
    cmd = "nvprof --events gld_request,gst_request ./sortTest sortTable " + str(colNum)+ " 4 > " + result
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_mem_ld_transaction" 
    cmd = "nvprof --events l1_global_load_hit,l1_global_load_miss ./sortTest sortTable " + str(colNum)+ " 4 > " + result
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_mem_st_transaction" 
    cmd = "nvprof --events global_store_transaction ./sortTest sortTable " + str(colNum)+ " 4 > " + result
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_inst" 
    cmd = "nvprof --events inst_issued,inst_executed ./sortTest sortTable " + str(colNum)+ " 4 > " + result
    os.system(cmd)

cmd= "rm -rf sortTable* sortKey"
os.system(cmd)
